//
//  DeviceManagerTableViewCell.m
//  Router
//
//  Created by teki on 15/10/14.
//  Copyright © 2015年 dc. All rights reserved.
//

#import "DeviceManagerTableViewCell.h"


@interface DeviceManagerTableViewCell ()
@property (weak, nonatomic) IBOutlet UILabel *userNameLabel;
//@property (weak, nonatomic) IBOutlet UILabel *uploadLabel;
//@property (weak, nonatomic) IBOutlet UILabel *downLoadLabel;
//@property (weak, nonatomic) IBOutlet UIButton *editButton;
@property (weak, nonatomic) IBOutlet UIButton *blackList;


@property (nonatomic, copy) AddToBlackListBlock block;
@end



@implementation DeviceManagerTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        // 初始化时加载Cell.xib文件
        NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:self options:nil];
        
        // 如果路径不存在，return nil
        if (arrayOfViews.count < 1)
        {
            return nil;
        }
        // 如果xib中view不属于UITableViewCell类，return nil
        if (![[arrayOfViews objectAtIndex:0] isKindOfClass:[UITableViewCell class]])
        {
            return nil;
        }
        // 加载nib
        self = [arrayOfViews objectAtIndex:0];
    }
    return self;
}



- (void)awakeFromNib {
    self.userNameLabel.textColor = SeparatorLineColor;
//    self.uploadLabel.textColor = SeparatorLineColor;
//    self.downLoadLabel.textColor = SeparatorLineColor;
    
    self.blackList.layer.cornerRadius = 5.0f;
    self.blackList.layer.masksToBounds = YES;
    [self.blackList setTitleColor:[UIColor colorWithHexString:@"#e1f5de"] forState:UIControlStateNormal];
    [self.blackList setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"#5ca954"]] forState:UIControlStateNormal];
    [self.blackList setTitleColor:SeparatorLineColor forState:UIControlStateSelected];
    [self.blackList setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"#e1f6de"]] forState:UIControlStateSelected];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void)setModel:(DeviceInfoModel *)model
{
    _model = model;
    self.userNameLabel.text = model.hostname;
}

/// 加到黑名单
- (IBAction)addToBlackListButtonPressed:(id)sender {
    if (self.block)
    {
        self.block(self.model);
    }
}



- (void)setAddToBlackListBlock:(AddToBlackListBlock)block
{
    _block = block;
}
@end
